package algotithm.acwing.kmp;

import java.io.*;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/19-23:43
输入：
3
aba
5
ababa
输出：
0 2
 */
public class Main {

    public static void main(String[] args) throws IOException,NumberFormatException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        // 模式串长度
        int n = Integer.parseInt(reader.readLine());
        // 模式串（短串）
        String str1 = reader.readLine();
        char[] p = new char[n+1];
        for (int i = 1; i <= n; i++) {
            p[i] = str1.charAt(i-1);
        }

        // 主串长度
        int m = Integer.parseInt(reader.readLine());
        // 主串
        String str2 = reader.readLine();
        char[] s = new char[m+1];
        for (int i = 1; i <= m ; i++) {
            s[i] = str2.charAt(i-1);
        }

        int[] pre = new int[n+1];
        for (int i = 2, j = 0; i <= n; i++) {
            while (j != 0 && p[i] != p[j+1]) {
                j = pre[j];
            }
            if (p[i] == p[j+1]) {
                j++;
            }
            pre[i] = j;
        }

        for (int i = 1, j = 0; i <= m; i++) {
            while (j != 0 && s[i] != p[j+1]) {
                j = pre[j];
            }
            if (s[i] == p[j+1]) {
                j++;
            }
            if (j == n) {
                writer.write(i-n + " ");
                j = pre[j];
            }

        }

        writer.flush();
        writer.close();
        reader.close();
    }

}
